package cn.ccb.struts2.common.converter;

import java.util.Map;

import cn.ccb.struts2.login.UserBean;

import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter;

public class UserBeanConverter extends DefaultTypeConverter {

	public Object  convertValue(Map context,Object value,Class toType)
	{
		if(toType == UserBean.class)
		{
			String[] params = (String[])value;
			UserBean user = new UserBean();
			String[] userValues = params[0].split(",");
			user.setUsername(userValues[0]);
			user.setPassword(userValues[1]);
			return user;
		}
		else if (toType == String.class)
		{
			UserBean user = (UserBean)value;
			return "<"+user.getUsername()+","+user.getPassword()+">";
		}
		return null;
	}
}
